﻿#region Namespace imports

using System;

#endregion

namespace AdventureGame
{
    internal class ArcadeMode
    {
        private static Int32 _points;
        private Hero hero = new Hero();

        private Rewards reward = new Rewards();

        public static void ArcadeModeBegin()
        {
            Console.WriteLine("Welcome to Arcade Mode!");
            Console.WriteLine();
            Hero.SpellHeal = true;
            Hero.SpellParalyze = true;
            Hero.SpellBlast = true;
            Hero.SpellPoison = true;
            Hero.SpellWeaken = true;
            Hero.SpellEnhance = true;

            Console.WriteLine();

            if (Level1())
            {
                _points = _points*2;
                Store();
                if (Level2())
                {
                    _points = _points*2;
                    Store();
                    if (Level3())
                    {
                        _points = _points*2;
                        Store();
                        if (Level4())
                        {
                            _points = _points*3;
                            Store();
                            if (FinalBattle())
                            {
                                Console.WriteLine("Congratulations!!!!");
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Finished!");
            Score();
        }

        private static Boolean Level1()
        {
            if (Combat.Battle("troll") == "win")
            {
                _points += 2;
                Rewards.Treasure("troll");
                if (Combat.DoubleBattle("troll", "troll") == "win")
                {
                    _points += 4;
                    Rewards.Treasure("troll group");
                    if (Combat.Battle("Witch") == "win")
                    {
                        _points += 6;
                        Rewards.Treasure("witch");
                        return true;
                    }
                }
            }
            return false;
        }

        private static Boolean Level2()
        {
            if (Combat.Battle("ogre") == "win")
            {
                _points += 2;
                Rewards.Treasure("troll");
                if (Combat.DoubleBattle("ogre", "ogre") == "win")
                {
                    _points += 4;
                    Rewards.Treasure("troll group");
                    if (Combat.Battle("dragon") == "win")
                    {
                        _points += 6;
                        Rewards.Treasure("witch");
                        return true;
                    }
                }
            }
            return false;
        }

        private static Boolean Level3()
        {
            if (Combat.Battle("zombie") == "win")
            {
                _points += 2;
                Rewards.Treasure("troll");
                if (Combat.DoubleBattle("zombie", "zombie") == "win")
                {
                    _points += 4;
                    Rewards.Treasure("troll group");
                    if (Combat.Battle("vampire") == "win")
                    {
                        _points += 6;
                        Rewards.Treasure("witch");
                        return true;
                    }
                }
            }
            return false;
        }

        private static Boolean Level4()
        {
            if (Combat.Battle("ninja") == "win")
            {
                _points += 2;
                Rewards.Treasure("troll");
                if (Combat.DoubleBattle("ninja", "ninja") == "win")
                {
                    _points += 4;
                    Rewards.Treasure("troll group");
                    if (Combat.Battle("spectre") == "win")
                    {
                        _points += 6;
                        Rewards.Treasure("witch");
                        return true;
                    }
                }
            }
            return false;
        }

        private static Boolean FinalBattle()
        {
            if (Combat.Battle("mormorda") == "win")
            {
                _points += 8;
                Console.WriteLine("Arcade Mode Complete!!!");
                return true;
            }
            return false;
        }

        private static void Store()
        {
            Console.WriteLine();
            Console.WriteLine("Welcome to the interlevel store!");
            Console.WriteLine("You may spend points here to acquire items.");
            Console.WriteLine("We have...");
            Console.WriteLine("Potions for 5 points");
            Console.WriteLine("Mana potions for 10 points");
            Console.WriteLine("Swords for 3 points");
            Console.WriteLine("Armor for 2 points");
            Console.WriteLine("Spellbooks for 4 points");
            Console.WriteLine("Cloaks for 3 points");
            Console.WriteLine("Capes for 5 points");
            Console.WriteLine("And Hawkeys for 4 points");


            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("You currently have {0} points", _points);
                Console.WriteLine();
                Console.WriteLine("What would you like to buy?");
                String command = Console.ReadLine();

                if (command == "what")
                {
                    Console.WriteLine("We have...");
                    Console.WriteLine("Potions for 5 points");
                    Console.WriteLine("Mana potions for 10 points");
                    Console.WriteLine("Swords for 3 points");
                    Console.WriteLine("Armor for 2 points");
                    Console.WriteLine("Spellbooks for 4 points");
                    Console.WriteLine("Cloaks for 3 points");
                    Console.WriteLine("Capes for 5 points");
                    Console.WriteLine("And Hawkeys for 4 points");
                }
                else if (command == "potion")
                {
                    if (_points >= 5)
                    {
                        Hero.SetPot(1);
                        _points -= 5;
                        Console.WriteLine("1 potion bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "mana potion")
                {
                    if (_points >= 10)
                    {
                        Hero.SetManaPot(1);
                        _points -= 10;
                        Console.WriteLine("1 mana potion bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "sword")
                {
                    if (_points >= 3)
                    {
                        Hero.SetAtk(2);
                        _points -= 5;
                        Console.WriteLine("1 sword bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "armor")
                {
                    if (_points >= 2)
                    {
                        Hero.SetDef(2);
                        _points -= 2;
                        Console.WriteLine("1 piece of armor bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "spellbook")
                {
                    if (_points >= 4)
                    {
                        Hero.SetMag(2);
                        _points -= 4;
                        Console.WriteLine("1 spellbook bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "cloak")
                {
                    if (_points >= 3)
                    {
                        Hero.SetRes(2);
                        _points -= 3;
                        Console.WriteLine("1 magic cloak bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "cape")
                {
                    if (_points >= 5)
                    {
                        Hero.SetEva(10);
                        _points -= 5;
                        Console.WriteLine("1 cape bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else if (command == "hawkeye")
                {
                    if (_points >= 4)
                    {
                        Hero.SetAcc(10);
                        _points -= 4;
                        Console.WriteLine("1 hawkeye bought.");
                    }
                    else
                    {
                        Console.WriteLine("You don't have enough points.");
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine("Your command is incomprehensible");
                }

                Console.WriteLine("Will that be all?");
                command = Console.ReadLine();
                if (command == "yes")
                {
                    return;
                }
                else
                {
                    continue;
                }
            }
        }

        private static void Score()
        {
            Console.WriteLine("Your score is: {0}", _points + Hero.GrabHp());
        }
    }
}